mod logger;
mod task_confs;
mod task_stat;
mod order;

use std::path::PathBuf;
use log::{info};
use tokio::time::Instant;
use clap::{Command, Arg, ArgAction, value_parser};
use task_confs::TaskConfs;

fn main() {
    let start = Instant::now();
    let matches = Command::new("mtask")
                    .version("0.1.0")
                    .about("Multiple configuration based tasks can be executed simultaneously. Even if there may be dependencies between these tasks.")
                    .arg(
                        Arg::new("dir")
                            .help("Directory for configuration files")
                            .required(true)
                            .value_parser(value_parser!(PathBuf))
                    ).arg(
                        Arg::new("verbose")
                            .short('v')
                            .help("Print more detailed information")
                            .action(ArgAction::Count)
                    ).get_matches();

    let count = matches.get_count("verbose");
    logger::init_log(count);

    let dir = matches.get_one::<PathBuf>("dir").unwrap();
    info!("dir = {:?}", dir);
    let mut tasks = TaskConfs::new();
    tasks.read_confs_from_dir(dir.to_path_buf());

    order::run(tasks);

    let duration = Instant::now().duration_since(start);
    info!("Time consumed : {:?}", duration);
}